package bb.action;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import bb.entity.Course;
import io.vertx.ext.web.RoutingContext;

@Controller
public class CourseAction {

	@Resource
	private SessionFactory sessionFactory;

	public void queryCourse(RoutingContext ctx) {

		Session session = sessionFactory.openSession();
		Query query = session.createQuery("from Course");

		ObjectMapper mapper = new ObjectMapper();
		try {
			List<Course> list = query.list();
			String str = mapper.writeValueAsString(list);
			ctx.response().putHeader("content-type", "text/html;charset=UTF-8").end("product:" + str);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

	}
}
